package cn.vconinfo.lims.delivery.mapper;

import cn.vconinfo.lims.delivery.entity.GeneralDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface GeneralManageMapper {

    @Select("SELECT COUNT(*) FROM basic_type_info\n" +
            "WHERE type_info_type = #{typeInfoType} AND `status` = 1\n" +
            "AND (type_info_name  LIKE concat('%', #{search}, '%')" +
            "OR type_info_code LIKE concat('%',  #{search}, '%'))")
    Long getGeneralCount(@Param("typeInfoType") Integer typeInfoType, @Param("search") String search);

//    @Select("SELECT type_info_id, type_info_name, type_info_code, bti.office_id, remarks, bi.object_name\n" +
//            "FROM basic_type_info bti\n" +
//            "LEFT JOIN basic_info bi ON bti.office_id = bi.object_id\n" +
//            "WHERE bti.`status` = 1 AND bti.type_info_type = #{typeInfoType}\n" +
//            "AND (type_info_name  LIKE concat('%', #{search}, '%')\n" +
//            "OR type_info_code LIKE concat('%', #{search}, '%'))\n" +
//            "LIMIT #{current},#{pageSize}\n")
//    List<GeneralDTO> generalQuery(@Param("current") Integer current, @Param("pageSize") Integer pageSize,
//                                  @Param("typeInfoType") Integer typeInfoType, @Param("search") String search);

//    @Select("SELECT * FROM basic_info\n" +
//            "WHERE `status` = 1 AND object_type = 0\n")
//    List<ObjectDTO> officeQuery();

    @Select("SELECT type_info_name FROM basic_type_info\n" +
            "WHERE type_info_type = #{typeInfoType} AND status = 1")
    List<String> typeInfoNameSelect(@Param("typeInfoType") Integer typeInfoType);

    @Insert("INSERT INTO basic_type_info\n" +
            "(type_info_name, type_info_code, office_id, remarks, type_info_type, age_ratio)\n" +
            "VALUES (#{typeInfoName}, #{typeInfoCode}, #{officeId}, #{remarks}, #{typeInfoType}, #{ageRatio})\n")
    Boolean generalInsert(@Param("typeInfoName") String typeInfoName, @Param("typeInfoCode") String typeInfoCode,
                          @Param("officeId") Long officeId, @Param("remarks") String remarks,
                          @Param("typeInfoType") Integer typeInfoType, @Param("ageRatio") Float ageRatio);

    @Update("UPDATE basic_type_info \n" +
            "SET `status` = 0 \n" +
            "WHERE type_info_id = #{typeInfoId} \n")
    Boolean generalDelete(@Param("typeInfoId") Long typeInfoId);

    @Update("UPDATE basic_type_info SET\n" +
            "type_info_name = #{typeInfoName}, type_info_code = #{typeInfoCode},\n" +
            "office_id = #{officeId},age_ratio = #{ageRatio}, remarks = #{remarks}\n" +
            "WHERE type_info_id = #{typeInfoId}")
    Boolean generalEdit(@Param("typeInfoName") String typeInfoName, @Param("typeInfoCode") String typeInfoCode,
                        @Param("officeId") Long officeId, @Param("ageRatio") Float ageRatio, @Param("remarks") String remarks,
                        @Param("typeInfoId") Long typeInfoId);

    @Select("SELECT * FROM basic_type_info WHERE type_info_type = 1 AND status = 1")
    List<GeneralDTO> getAllTypeInfo();

    @Select("SELECT * FROM basic_type_info WHERE type_info_type = 3 AND status = 1")
    List<GeneralDTO> getDepartmentInfo();

    @Select("SELECT * FROM basic_type_info WHERE type_info_type = 4 AND status = 1")
    List<GeneralDTO> getSexType();

    @Select("SELECT * FROM basic_type_info WHERE type_info_type = 2 AND status = 1")
    List<GeneralDTO> getAllSampleType();

    @Select("SELECT type_info_name FROM basic_type_info WHERE type_info_id = #{typeInfoId}")
    String getGeneralName(@Param("typeInfoId") Long typeInfoId);
}
